package com.wuyong.Chapter3;

import java.util.Random;
import java.util.Stack;

public class TestMain {

    public static void main(String[] args) {
//        ArrayStack<Integer> stack = new ArrayStack<>();
//        for (int i = 0; i < 5; i++) {
//            stack.push(i);
//            System.out.println("stack = " + stack + "");
//        }
//        stack.pop();
//        System.out.println("stack = " + stack + "");
//
//        System.out.println("args = [" + test() + "]");
        long opNumber = 100000;
        double time1 = testQueue(new ArrayQueue<>(), opNumber);
        System.out.println("time1 = [" + time1 + "]");
        double time2 = testQueue(new LoopQueue<>(), opNumber);
        System.out.println("time2 = [" + time2 + "]");
    }

    public static String test = "(sfhsfsdj(fnsdfkjs){fffsfsdfsd}[fsdfdfsdfg]";

    public static boolean test() {
        Stack<Character> stack = new Stack<>();
        char[] arr = test.toCharArray();
        for (char c : arr) {
            if (c == '(' || c == '{' || c == '[') {
                stack.push(c);
            } else if (c == ')' || c == '}' || c == ']') {
                char topChar = stack.pop();
                if (c == ')' && topChar != '(') {
                    return false;
                }
                if (c == '}' && topChar != '{') {
                    return false;
                }
                if (c == ']' && topChar != '[') {
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }

    public static  double testQueue(Queue<Integer> queue, long opNumber) {
        long startTime = System.nanoTime();

        Random random = new Random();
        for (int i = 0; i < opNumber; i++) {
            queue.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opNumber; i++) {
            queue.dequeue();
        }

        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

}
